/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAL;

import DTO.dThanphien;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author nvc11190
 */
public class Thanphien {
    MyConnect conn;
   
    
    public Thanphien()
    {
        conn = new MyConnect();
    }
    
    public ResultSet Loadthanphien1()
    {
        return conn.excuteQuery("select a.ma_xuat [Mã Đơn Xuất], convert(varchar, a.ngay, 101) [Ngày Xuất], b.ten [Tên Khách], b.dia_chi [Địa Chỉ], c.ten_sp [Tên Sản Phẩm], c.tg_baohanh [Thời gian bảo hành] from xuat_hang a, khach_hang b, san_pham c where a.ma_khach=b.ma_khach and a.ma_sp=c.ma_sp");
    }
    public ResultSet SearchKhach(String name)
    {
        return conn.excuteQuery("select a.ma_xuat [Mã Đơn Xuất], convert(varchar, a.ngay, 101) [Ngày Xuất], b.ten [Tên Khách], b.dia_chi [Địa Chỉ], c.ten_sp [Tên Sản Phẩm], c.tg_baohanh [Thời gian bảo hành] from xuat_hang a, khach_hang b, san_pham c where a.ma_khach=b.ma_khach and a.ma_sp=c.ma_sp and b.ten Like N'%"+name+"%'");
    }
    public ResultSet CountThanPhien()
    {
        return conn.excuteQuery("select COUNT(*) from than_phien");
    }
    
    public int AddThanphien(dThanphien dtp) throws SQLException
    {
        return conn.executeUpdate("insert into than_phien values('"+dtp.getMa_tp()+"',(select ma_khach from khach_hang where ten=N'"+dtp.getMa_khach()+"'),'"+dtp.getMa_xuat()+"','"+dtp.getMa_nv()+"',(select ma_phong from phong_ban where ten=N'"+dtp.getMa_phong()+"'),N'"+dtp.getTen_sp()+"',N'"+dtp.getNoi_dung()+"',N'"+dtp.getTinh_trang()+"',N'"+dtp.getBao_hanh()+"',0,0,'"+dtp.getNgay()+"')");
    }
    
}
